<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编程式的导航</title>
    <script src="./../vue/vue.js"></script>
    <script src="./../vue/vue-router.js"></script>
</head>
<body>

    <div id="app">
        <div>
            <ul>
                <li><a href="#" @click.prevent="onClickJump">点击跳转</a></li>
            </ul>
        </div>
        <router-view></router-view>
    </div>

    <script>
        const TestJump = {
            template: `
            <div>TestJump</div>
            `
        }
        const Test = {
            template: `
            <div>test</div>
            `
        }

        const router = new VueRouter({
            routes: [
                {
                    path: '/test',
                    component: Test
                },
                {
                    path: '/jump',
                    component: TestJump
                }
            ]
        })

        let vm = new Vue({
            router,
            el: "#app",
            data: {

            },
            methods: {
                onClickJump(){
                    if(this.$route.path === "/jump"){
                        router.replace("test")
                    }else{
                        router.replace("jump")

                    }
                }
            },
        })

    </script>
    
</body>
</html>